﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using WPGame.StateManager;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Input.Touch;
using Microsoft.Xna.Framework.Graphics;
using WPGame.ResourceManager;
using WPGame.Objects;
using WPGame.Graphics;

namespace WPGame.States
{
    class MenuState : GState
    {
        private Sprite m_Background;
        private Button m_PlayButton;
        private Button m_LevelButton;
        private Button m_OptionButton;
        private Button m_InfoButton;
        private Button m_MoreButton;

        private String _string;
        private GTimer m_Timer;

        public MenuState(eGStateGame id)
            : base(id)
        {
           this.enabledGesture = GestureType.Tap;
        }

        public override void InitStateGame(ContentManager Content) 
        {
            GSpriteFactory.getInstance().Init(Content);

            m_Background = GSpriteFactory.getInstance().getSprite(eGSprite.BACKGROUND);
            //Playbutton
            m_PlayButton = new Button(new Vector2(GGlobalSetting.ScreenWidth / 2 - GSpriteFactory.getInstance().getSprite(eGSprite.PLAY_BUTTON).Bound.Width / 2, 340.0f),
                                      GSpriteFactory.getInstance().getSprite(eGSprite.PLAY_BUTTON)  
                                      );
            m_LevelButton = new Button(new Vector2(100,545), GSpriteFactory.getInstance().getSprite(eGSprite.SELECT_LEVEL_BUTTON));
            m_MoreButton = new Button(new Vector2(211, 645), GSpriteFactory.getInstance().getSprite(eGSprite.MORE_BUTTON));
            m_OptionButton = new Button(new Vector2(143, 645), GSpriteFactory.getInstance().getSprite(eGSprite.OPTION_BUTTON));
            m_InfoButton = new Button(new Vector2(280, 645), GSpriteFactory.getInstance().getSprite(eGSprite.INFO_BUTTON));

            //Gán hàm vào biến delegate Action
            m_PlayButton.actionFunc = new Button.Action(goPlayState);

            _string = "";
            m_Timer = new GTimer();

            base.InitStateGame(Content);
        }

        public override void UpdateState(GameTime gameTime)
        {
            
            base.UpdateState(gameTime);
        }

        public override void HandleInput(GameTime gameTime, GInputState Input)
        {
            m_PlayButton.HandleInput(Input);
            if (m_PlayButton.Status == eGStatusButton.NORMAL)
            {
                _string = "";
            }
            base.HandleInput(gameTime, Input);
        }

        public override void Render(SpriteBatch spriteBatch)
        {
            m_Background.Render(spriteBatch);
            spriteBatch.DrawString(GSpriteFactory.getInstance().getFont(eGFont.ARIAL_FONT), "In Menu State.", new Vector2(GGlobalSetting.ScreenWidth / 2, 100) , Color.White);
            spriteBatch.DrawString(GSpriteFactory.getInstance().getFont(eGFont.ARIAL_FONT), _string, new Vector2(100, 200), Color.White);
           
            m_PlayButton.Render(spriteBatch);
            m_MoreButton.Render(spriteBatch);
            m_InfoButton.Render(spriteBatch);
            m_LevelButton.Render(spriteBatch);
            m_OptionButton.Render(spriteBatch);
        }

        private void goPlayState()
        {
            _string = "Tap!...";
            GStateManager.getInstance().ExitState();
            GStateManager.getInstance().AddState(new PlayState(eGStateGame.PLAY));
        }
    }
}
